package service;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class BaseService {
    private SqlSessionFactory ssf;
    private SqlSession session;
    public <T> T getMapper(Class<T> c) throws IOException {
        InputStream in = Resources.getResourceAsStream("config.xml");
        ssf = new SqlSessionFactoryBuilder().build(in);
        session = ssf.openSession();
        return session.getMapper(c);
    }

    public SqlSession getSession() {
        return session;
    }
}
